#pragma once
#include <pthread.h>

namespace CondModule
{
    class Cond
    {
        public:
        Cond(const Cond&) = delete;
        const Cond &operator=(const Cond&) = delete;
        Cond()
        {
            pthread_cond_init(&_cond, nullptr);
        }
        
        void Wait(pthread_mutex_t* mutex)
        {
            int n = pthread_cond_wait(&_cond, mutex);
            (void)n;
        }

        void Signal()
        {
            // 唤醒在条件变量下等待的一个线程
            int n = pthread_cond_signal(&_cond);
            (void)n;
        }

        void Broadcast()
        {
            // 唤醒所有在条件变量下等待的线程
            int n = pthread_cond_broadcast(&_cond);
            (void)n;
        }

        ~Cond()
        {
            pthread_cond_destroy(&_cond);
        }
        private:
        pthread_cond_t _cond;
    };
}